/*
 * @页面名称:主页面按钮事件
 * @描述:
 * @作者:
 * @Date:
 */
import { useDynamicStore } from "@/stores/modules/dynamic";
import vueAxios from "@/api/index";
import { useAppStore } from "@/stores/modules/app";
import { useUserStore } from "@/stores/modules/user";
import { useFondsStore } from "@/stores/modules/fonds";
import { useCatalogStore } from "@/stores/modules/catalog";
import { TestClass } from "./ts/test";
import { IsLockConcat } from "./ts/pubulic";
import RuleClass from "./ts/FieldRule";
import { cloneDeep } from "lodash-es";
import { reactive } from "vue";
import ACrypto from "@/utils/crypto";
import dtime from "moment";
import { saveAs } from "file-saver";
import { columnCoverter, removeBlock } from "@/views/system/dynamicMain/ts/until";
import global from "@/utils/SnowflakeClass";
import { ElNotification } from "element-plus";
import ReportFormClass from "./ts/ReportForm";
import { ElMessage, ElMessageBox } from "element-plus";
import { getSysConfig } from "@/utils/util";

export class ButtonClick {
  dynamicStore: any;
  appStore: any;
  userStore: any;
  fondsStore: any;
  catalogStore: any;
  constructor() {
    this.dynamicStore = useDynamicStore();
    this.appStore = useAppStore();
    this.userStore = useUserStore();
    this.fondsStore = useFondsStore();
    this.catalogStore = useCatalogStore();
  }
  /**
   * @description 主表按钮事件
   * @param
   * @param
   * @returns
   */
  async ParentClickEvent(name: string, proxy: any) {
    proxy.dynamicModal.type = "folder";
    const { tableSelect } = this.dynamicStore;
    const { userInfo } = this.userStore;
    const { treeNode } = this.catalogStore;
    const stateNum: any = {
      Collect: 1,
      Arrangement: 2,
      Storage: 3,
      Utilization: 4
    };
    const defaultData = {
      Year: null,
      Code: "",
      Order: "",
      PageCount: "",
      Parent_ID: this.dynamicStore.childLeftClick ? "" : proxy.fatherObj ? proxy.fatherObj.Record_ID : "",
      Catalog_ID: this.dynamicStore.childLeftClick
        ? this.catalogStore.treeNode.Catalog_ID
        : proxy.fatherObj
        ? proxy.fatherObj.Catalog_ID
        : this.catalogStore.treeNode.Catalog_ID,
      Status: stateNum[proxy.routeData.status],
      Fonds_ID: this.catalogStore.treeNode.Fonds_ID,
      Create_DateTime: new Date()
    };
    console.log(proxy.fatherObj, this.catalogStore.treeNode.Catalog_ID);

    switch (name) {
      case "加一个按键":
        proxy.$message.success("测试");
        break;
      case "新增":
        const isCanAdd = getSysConfig("parentNodeCanAdd");
        // if (isCanAdd !== "1" && treeNode.children) {
        //   proxy.$alert("非叶子节点,不可添加数据!", "提示", {
        //     confirmButtonText: "知道了",
        //     type: "warning"
        //   });
        //   return;
        // }
        proxy.dynamicModal.title = "新增";
        await vueAxios
          .post("Master_Base_EditorWindow/GetConditional", {
            order: "EW_Order asc",
            dtoList: [{ fieldName: "FMT_ID", fieldValue: proxy.routeData.fmtid }]
          })
          .then((res: any) => {
            if (Object.keys(res.List).length > 0) {
              this.dynamicStore.setOldForm({});
              this.dynamicStore.setModalFormData(defaultData);
              const stateName: any = {
                Collect: "档案收集",
                Arrangement: "档案整理",
                Storage: "档案保存",
                Utilization: "档案利用"
              };
              res.List.forEach((item: any) => {
                if (item.EW_Type === stateName[this.fondsStore.fondsObj.Archive_Status]) {
                  proxy.dynamicModal.htmlCode = item.EW_Det;
                  proxy.dynamicModal.formType = 1;
                  proxy.$refs.dynamicForm.open();
                } else if (item.EW_Type === "空") {
                  proxy.dynamicModal.htmlCode = item.EW_Det;
                  proxy.dynamicModal.formType = 1;
                  proxy.$refs.dynamicForm.open();
                }
              });
            } else {
              proxy.$message.error("请前往窗口模型配置相关参数!");
            }
          });
        break;
      case "修改":
        proxy.dynamicModal.title = "修改";
        this.dynamicStore.setOldForm(cloneDeep(tableSelect[0]));
        vueAxios
          .post("Master_Base_EditorWindow/GetConditional", {
            order: "EW_Order asc",
            dtoList: [{ fieldName: "FMT_ID", fieldValue: tableSelect[0].FMT_ID }]
          })
          .then((res: any) => {
            if (Object.keys(res.List[0]).length > 0) {
              this.dynamicStore.setModalFormData(cloneDeep(tableSelect[0]));
              const stateName: any = {
                Collect: "档案收集",
                Arrangement: "档案整理",
                Storage: "档案保存",
                Utilization: "档案利用"
              };
              res.List.forEach((item: any) => {
                if (item.EW_Type === stateName[this.fondsStore.fondsObj.Archive_Status]) {
                  proxy.dynamicModal.htmlCode = item.EW_Det;
                  proxy.dynamicModal.formType = 1;
                  proxy.$refs.dynamicForm.open();
                } else if (item.EW_Type === "空") {
                  proxy.dynamicModal.htmlCode = item.EW_Det;
                  proxy.dynamicModal.formType = 1;
                  proxy.$refs.dynamicForm.open();
                }
              });
            } else {
              proxy.$message.error("请前往窗口模型配置相关参数!");
            }
          });
        break;
      case "克隆":
        proxy.dynamicModal.title = "克隆";
        this.dynamicStore.setOldForm({});
        vueAxios
          .post("Master_Base_EditorWindow/GetConditional", {
            order: "EW_Order asc",
            dtoList: [{ fieldName: "FMT_ID", fieldValue: tableSelect[0].FMT_ID }]
          })
          .then((res: any) => {
            if (Object.keys(res.List[0]).length > 0) {
              // 触发字段规则校验函数
              // 获取启用的字段规则
              const stateNum: any = {
                Collect: 1,
                Arrangement: 2,
                Storage: 3,
                Utilization: 4
              };
              const newData = reactive({ ...tableSelect[0], Status: stateNum[proxy.routeData.status] });
              const fieldRule = this.dynamicStore.visibleConfig.FieldRule.filter((v: any) => v.FR_Enable === true);
              const tableName = this.dynamicStore.visibleConfig.FMT.FMT_TableName;
              const newTestClass = new TestClass(newData, fieldRule, tableName);
              newTestClass.checkout();
              this.dynamicStore.setModalFormData(newData);
              proxy.dynamicModal.htmlCode = res.List[0].EW_Det;
              proxy.dynamicModal.formType = 1;
              proxy.$refs.dynamicForm.open();
            } else {
              proxy.$message.error("请前往窗口模型配置相关参数!");
            }
          });
        break;
      case "删除":
        {
          proxy
            .$confirm("是否删除当前数据?", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning"
            })
            .then(async () => {
              let { visibleConfig, tableSelect, tableData } = this.dynamicStore;
              proxy.singalrModal.visible = true;
              let deleteFailed = false; // 定义一个变量来标记是否有删除失败
              if (!proxy.singalrModal.AllNetworkStatus) {
                proxy.singalrModal.AllNetworkStatus = true;
                proxy.singalrModal.circulatingIndex = 0;
                proxy.singalrModal.percent = 0;
              }
              const copyData = cloneDeep(tableSelect);
              for (let i = proxy.singalrModal.circulatingIndex; i < copyData.length; i++) {
                proxy.singalrModal.circulatingIndex = i;
                const item = copyData[i];
                proxy.singalrModal.text = `正在删除${proxy.singalrModal.circulatingIndex}个数据，档号为${item.Code}`;
                if (proxy.singalrModal.networkStatus && proxy.singalrModal.AllNetworkStatus) {
                  const isDelete = getSysConfig("isShowRecycle");
                  let Res;
                  if (isDelete && isDelete.toLowerCase() === "true") {
                    Res = await proxy.$vueAxios.put(
                      "Dynamic",
                      {
                        list: [{ Record_ID: item.Record_ID, FMT_ID: item.FMT_ID, FM_ID: item.FM_ID, IsDelete: true }],
                        tableName: visibleConfig.FMT.FMT_TableName
                      },
                      { noLoading: true }
                    );
                  } else {
                    Res = await proxy.$vueAxios.delete2(
                      "Dynamic",
                      {
                        list: [{ Record_ID: item.Record_ID, FMT_ID: item.FMT_ID, FM_ID: item.FM_ID, IsDelete: true }],
                        tableName: visibleConfig.FMT.FMT_TableName
                      },
                      { noLoading: true }
                    );
                  }
                  if (Res.Mark) {
                    this.dynamicStore.delTableSelectData(
                      tableSelect.splice(
                        tableSelect.findIndex((v: any) => v.Record_ID === item.Record_ID),
                        1
                      )
                    );
                    tableData.splice(
                      tableData.findIndex((v: any) => v.Record_ID === item.Record_ID),
                      1
                    );
                    this.dynamicStore.setChildTableData([]);
                  } else {
                    deleteFailed = true; // 标记删除失败
                  }
                  proxy.singalrModal.percent = Math.round(((proxy.singalrModal.circulatingIndex + 1) / copyData.length) * 100);
                } else {
                  return;
                }
              }
              if (deleteFailed) {
                proxy.$message({
                  type: "error",
                  message: "删除失败!"
                });
              } else {
                proxy.$message({
                  type: "success",
                  message: "删除成功!"
                });
              }
              proxy.singalrModal.circulatingIndex = 0;
              proxy.singalrModal.percent = 0;
              proxy.singalrModal.visible = false;
              proxy.singalrModal.discontinueStatus = false;
              proxy.singalrModal.networkStatus = true;
              proxy.singalrModal.discontinueFont = "中止";
              proxy.singalrModal.AllNetworkStatus = false;
            });
        }
        break;
      case "前端导出":
        if (tableSelect.length === 0) {
          ElNotification.warning({
            title: "提示",
            message: "未选中任何数据!"
          });
          return false;
        }
        const catalogList = this.catalogStore.catalogList;
        const { visibleConfig } = this.dynamicStore;
        const fieldRule = visibleConfig.FieldRule.filter((v: any) => v.FR_Enable === true);
        const str = "DDM_Enable_Display_" + proxy.routeData.status;
        const filterColumns = this.dynamicStore.visibleConfig.DDMList.filter(
          (v: any) => v[str] === true && v.Field_Name !== "IsLock"
        );
        const header = filterColumns.map((v: any) => v.DDM_CNName);
        const filterVal = filterColumns.map((v: any) => v.Field_Name);
        const { LoadingConfig } = this.appStore;
        LoadingConfig.contentLoading = true;
        const data = tableSelect.map((v: any) =>
          filterVal.map((j: string | number) => {
            for (let item of fieldRule) {
              if (item.FR_Rule.toLowerCase().includes("jm")) {
                v[j] = item.FR_TableField === j ? ACrypto.getSS(v[j]) : v[j];
              } else if (item.FR_Rule.toLowerCase().includes("userinfo:")) {
                // 人员的id转换
              } else if (item.FR_Rule.toLowerCase().includes("catalogconvert:")) {
                // 分类转换
                v[j] =
                  item.FR_TableField === j
                    ? catalogList.find((k: any) => k.Catalog_ID && k.Catalog_ID === v[j]).Catalog_Name
                    : v[j];
              } else if (item.FR_Rule.toLowerCase().includes("datetime:")) {
                // 时间转换
                v[j] = item.FR_TableField === j && v[j] ? dtime(v[j]).format("YYYY-MM-DD") : v[j];
              } else if (item.FR_Rule.includes("dictionary:")) {
                v[j] = item.FR_TableField === j ? columnCoverter(item.FR_Rule, v[j]) : v[j];
              }
            }
            return v[j];
          })
        );
        import("@/vendor/Export2Excel").then(excel => {
          excel.export_json_to_excel({
            header: header, //表头 必填
            data, //具体数据 必填
            filename: "主表格业务数据表", //非必填
            autoWidth: true, //非必填
            bookType: "xlsx" //非必填
          });
          LoadingConfig.contentLoading = false;
        });
        break;
      case "目录二维码":
        proxy.QRCode1.open();
        break;
      case "数据二维码":
        proxy.QRCode2.open();
        break;
      case "修改分类":
        proxy.SortModalRef.open();
        break;
      case "打包":
        proxy.$showLoading({ tip: "正在打包..." });
        const params = {
          fmtId: tableSelect[0].FMT_ID,
          ids: tableSelect.map((v: any) => v.Record_ID),
          clientUser: proxy.signalr.connectionId,
          fonds_ID: tableSelect[0].Fonds_ID,
          tableName: this.dynamicStore.visibleConfig.FMT.FMT_TableName
        };
        vueAxios.post("InterfaceDownload/DownloadZip", params, { noLoading: true }).then(res => {
          if (res.Mark) {
            proxy.$hideLoading();
            proxy.$message.success("打包成功!");
          }
        });
        break;
      case "打包下载全文":
        proxy.$showLoading({ tip: "正在打包..." });
        const params2 = {
          fmtId: tableSelect[0].FMT_ID,
          ids: tableSelect.map((v: any) => v.Record_ID),
          clientUser: proxy.signalr.connectionId,
          fonds_ID: tableSelect[0].Fonds_ID,
          tableName: this.dynamicStore.visibleConfig.FMT.FMT_TableName
        };
        vueAxios.post("InterfaceDownload/GetZipByAllInfos", params2, { noLoading: true }).then(res => {
          if (res.Mark) {
            proxy.$hideLoading();
            proxy.$message.success("打包成功!");
          } else {
            proxy.$hideLoading();
            proxy.$message.error("打包失败!");
          }
        });
        break;
      case "移交下一环节":
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "核对数据";
        proxy.handoverSetting.data = tableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.retreat = false;
        break;
      case "退回上一步":
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "核对数据";
        proxy.handoverSetting.data = tableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.retreat = true;
        break;
      case "导出归档登记表":
        // if (tableSelect.length === 0) {
        //   ElNotification.warning({
        //     title: "提示",
        //     message: "未选中任何数据!"
        //   });
        //   return false;
        // }
        // vueAxios.post("Excel/ExportFilingData", { list: tableSelect }).then((res: any) => {});
        break;
      case "导出归档目录清单":
        if (tableSelect.length === 0) {
          ElNotification.warning({
            title: "提示",
            message: "未选中任何数据!"
          });
          return false;
        }
        const fileData = await vueAxios.download("Excel/ExportListingData", { list: tableSelect });
        const fileBlob = new Blob([fileData], { type: "application/octet-stream;charset=utf-8" });
        saveAs(fileBlob, "归档目录清单.xlsx");
        break;
      case "批量挂接全文":
        proxy.uploadConfig.visible = true;
        break;
      case "轨迹查看":
        // proxy.TrailConfig.visible = true;
        proxy.TrailConfig.title = "轨迹查看";
        proxy.TrailConfig.data = tableSelect[0];
        proxy.TrailRef.show();
        break;
      case "OCR":
        vueAxios
          .post(
            "MasterBaseSearchOCR/TableExecuteOCR",
            {
              tableName: proxy.FMTData.filter((v: any) => v.FMT_ID === proxy.routeData.fmtid)[0].FMT_TableName,
              clientUser: proxy.signalr.connectionId
            },
            {
              noLoading: true
            }
          )
          .then((res: any) => {
            console.log(res);
          });
        break;
      case "权限管理":
        proxy.AuthConfig.visible = true;
        proxy.AuthConfig.title = "权限管理";
        proxy.AuthConfig.type = "folder";
        break;
      case "离线挂接":
        proxy.mountSetting.visible = true;
        proxy.mountConfig.type = "folder";
        proxy.mountForm?.resetFields();
        break;
      case "复制":
        proxy.pasteSetting.is_Copy = true;
        proxy.$message.success("复制成功");
        this.dynamicStore.setCopyData(tableSelect);
        break;
      case "粘贴":
        proxy.$messageBox
          .confirm(`你确定要粘贴${tableSelect.length}项数据吗`, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(() => {
            proxy.pasteSetting.type = "folder";
            proxy.pasteSetting.visible = true;
          });
        break;
      case "剪贴":
        proxy.pasteSetting.is_Copy = false;
        proxy.$message.success("剪切成功");
        this.dynamicStore.setCopyData(tableSelect);
        break;
      case "流水操作":
        if (
          this.dynamicStore.visibleConfig.FieldRule.filter(
            (v: any) => v.FR_Enable === true && v.FR_TableField === "Order" && v.FR_RuleType === "trigger"
          ).length === 0
        ) {
          proxy.$message.error("大流水号规则未配置");
          return;
        }
        proxy.LSHSetting.visible = true;
        proxy.LSHSetting.type = 1;
        proxy.LSHSetting.title = "大流水操作";
        proxy.LSHSetting.orderType = "Order";
        proxy.LSHSetting.ruleList = this.dynamicStore.visibleConfig.FieldRule.filter((v: any) => v.FR_Enable === true);
        proxy.LSHSetting.tableName = this.dynamicStore.visibleConfig.FMT.FMT_TableName;
        const filedRule = removeBlock(
          this.dynamicStore.visibleConfig.FieldRule.filter((v: any) => v.FR_Enable === true && v.FR_TableField === "Order")[0]
            .FR_Rule
        );
        const filedRuleArr = filedRule.split(":").slice(2);

        const dtoList = filedRuleArr.map((v: any) => ({
          fieldName: v,
          fieldValue: this.dynamicStore.tableSelect[0][v],
          conditionalType: 0
        }));
        dtoList.push({ fieldName: "IsDelete", fieldValue: "nullorfalse", conditionalType: 0 });
        await vueAxios
          .post(
            `Dynamic/GetTableDataConditional?FMT_TableName=${this.dynamicStore.visibleConfig.FMT.FMT_TableName}`,
            {
              order: "Order asc",
              dtoList,
              pageIndex: 1,
              pageSize: 30000
            },
            { noLoading: true }
          )
          .then((res: any) => {
            if (res.Mark) {
              proxy.LSHSetting.data = res.List;
            }
          });
        break;
      case "小流水操作":
        {
          if (
            this.dynamicStore.visibleConfig.FieldRule.filter(
              (v: any) => v.FR_Enable === true && v.FR_TableField === "SmallOrder" && v.FR_RuleType === "trigger"
            ).length === 0
          ) {
            proxy.$message.error("小流水号规则未配置");
            return;
          }
          proxy.LSHSetting.type = 1;
          proxy.LSHSetting.visible = true;
          proxy.LSHSetting.title = "小流水操作";
          proxy.LSHSetting.orderType = "SmallOrder";
          proxy.LSHSetting.ruleList = this.dynamicStore.visibleConfig.FieldRule.filter((v: any) => v.FR_Enable === true);
          proxy.LSHSetting.tableName = this.dynamicStore.visibleConfig.FMT.FMT_TableName;
          // console.log(this.dynamicStore.childVisibleConfig.FMT.FMT_TableName);
          const filedRule = removeBlock(
            this.dynamicStore.visibleConfig.FieldRule.filter(
              (v: any) => v.FR_Enable === true && v.FR_TableField === "SmallOrder" && v.FR_RuleType === "trigger"
            )[0].FR_Rule
          );
          const filedRuleArr = filedRule.split(":").slice(2);
          const dtoList = filedRuleArr.map((v: any) => ({
            fieldName: v,
            fieldValue: this.dynamicStore.tableSelect[0][v],
            conditionalType: 0
          }));
          dtoList.push({ fieldName: "IsDelete", fieldValue: "nullorfalse", conditionalType: 0 });
          await vueAxios
            .post(
              `Dynamic/GetTableDataConditional?FMT_TableName=${this.dynamicStore.visibleConfig.FMT.FMT_TableName}`,
              {
                order: "Order asc",
                dtoList: [...dtoList],

                pageIndex: 1,
                pageSize: 30000
              },
              { noLoading: true }
            )
            .then((res: any) => {
              if (res.Mark) {
                proxy.LSHSetting.data = res.List;
              }
            });
        }
        break;
      case "标记备注":
        proxy.remarkForm?.resetFields();
        proxy.remarkSetting.visible = true;
        proxy.remarkSetting.type = "folder";
        break;
      case "数据查重":
        proxy.dataCheckForm?.resetFields();
        proxy.dataCheckSetting.visible = true;
        proxy.dataCheckSetting.type = "folder";
        break;
      case "查找替换":
        proxy.ReplacementConfig.type = 1;
        proxy.replaceModal.show(proxy.tableSetting.columns);
        break;
      case "文件锁定":
        let flag = false;
        flag = tableSelect.every((v: any) => v.Collect_Create_By === userInfo.U_ID) || userInfo.U_IsAdministrator;
        if (!flag) {
          proxy.$alert("没有操作权限!", "提示", {
            confirmButtonText: "知道了",
            type: "warning"
          });
          return;
        }
        IsLockConcat("parent", true).then(() => {
          proxy.$message.success("操作成功!");
        });
        break;
      case "文件解锁":
        let flag2 = false;
        flag2 = tableSelect.every((v: any) => v.Collect_Create_By === userInfo.U_ID) || userInfo.U_IsAdministrator;
        if (!flag2) {
          proxy.$alert("没有操作权限!", "提示", {
            confirmButtonText: "知道了",
            type: "warning"
          });
          return;
        }
        IsLockConcat("parent", false).then(() => {
          proxy.$message.success("操作成功!");
        });
        break;
      case "数据提交":
        const filterData = tableSelect.filter((v: any) => v.Status === 11);
        if (filterData.length > 0) {
          proxy.$message.warning("选中数据中包含不符合条件的数据，请检查数据状态");
          return;
        }
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "数据提交";
        proxy.handoverSetting.data = tableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.StatusValue = 11;

        break;
      case "数据撤回":
        const filterData2 = tableSelect.filter((v: any) => v.Status === 1 || v.Status === 12);
        if (filterData2.length > 0) {
          proxy.$message.warning("选中数据中包含不符合条件的数据，请检查数据状态");
          return;
        }
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "数据撤回";
        proxy.handoverSetting.data = tableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.retreat = false;
        proxy.handoverSetting.StatusValue = 1;
        break;
      case "数据接收":
        const filterData3 = tableSelect.filter((v: any) => v.Status !== 11);
        if (filterData3.length > 0) {
          proxy.$message.warning("选中数据中包含不符合条件的数据，请检查数据状态");
          return;
        }
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "数据接收";
        proxy.handoverSetting.data = tableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.StatusValue = 2;
        break;
      case "数据退回":
        // const filterData4 = tableSelect.filter((v: any) => v.Status !== 21 || v.Status !== 22);
        // if (filterData4.length > 0) {
        //   proxy.$message.warning("选中数据中包含不符合条件的数据，请检查数据状态");
        //   return;
        // }
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "数据退回";
        proxy.handoverSetting.data = tableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.StatusValue = 12;
        break;
      case "撤销接收":
        const filterData5 = tableSelect.filter((v: any) => v.Status !== 2);
        if (filterData5.length > 0) {
          proxy.$message.warning("选中数据中包含不符合条件的数据，请检查数据状态");
          return;
        }
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "撤销接收";
        proxy.handoverSetting.data = tableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.StatusValue = 11;
        break;
      case "移交入库":
        const filterData6 = tableSelect.filter((v: any) => v.Status === 21 || v.Status === 11);
        if (filterData6.length > 0) {
          proxy.$message.warning("选中数据中包含不符合条件的数据，请检查数据状态");
          return;
        }
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "移交入库";
        proxy.handoverSetting.data = tableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.StatusValue = 21;
        break;
      case "入库确认":
        const filterData7 = tableSelect.filter((v: any) => v.Status !== 21);
        if (filterData7.length > 0) {
          proxy.$message.warning("选中数据中包含不符合条件的数据，请检查数据状态");
          return;
        }
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "入库确认";
        proxy.handoverSetting.data = tableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.StatusValue = 3;
        break;
      case "撤销入库":
        const filterData8 = tableSelect.filter((v: any) => v.Status !== 21);
        if (filterData8.length > 0) {
          proxy.$message.warning("选中数据中包含不符合条件的数据，请检查数据状态");
          return;
        }
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "撤销入库";
        proxy.handoverSetting.data = tableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.StatusValue = 2;
        break;
      case "退回整编":
        const filterData9 = tableSelect.filter((v: any) => v.Status !== 3 && v.Status !== 21);
        console.log(filterData9);

        if (filterData9.length > 0) {
          proxy.$message.warning("选中数据中包含不符合条件的数据，请检查数据状态");
          return;
        }
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "退回整编";
        proxy.handoverSetting.data = tableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.StatusValue = 22;
        break;
      case "数据开放":
        const filterData10 = tableSelect.filter((v: any) => v.Status !== 3 || v.Open === true);
        if (filterData10.length > 0) {
          proxy.$message.warning("选中数据中包含不符合条件的数据，请检查数据状态");
          return;
        }
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "数据开放";
        proxy.handoverSetting.data = tableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.openStatus = true;
        proxy.handoverSetting.StatusValue = 100;
        break;
      case "取消开放":
        const filterData11 = tableSelect.filter((v: any) => v.Status !== 3 || v.Open === false);
        if (filterData11.length > 0) {
          proxy.$message.warning("选中数据中包含不符合条件的数据，请检查数据状态");
          return;
        }
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "取消开放";
        proxy.handoverSetting.data = tableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.openStatus = false;
        proxy.handoverSetting.StatusValue = 100; // 100代表不走规则
        break;
      case "合卷":
        const ftmPid = proxy.FMTData.filter((v: any) => v.FMT_ID === proxy.routeData.fmtid)[0].FMT_Parent_ID;
        console.log(proxy.FMTData.filter((v: any) => v.FMT_ID === ftmPid));
        break;
      case "拆卷":
        {
          const filterData = tableSelect.filter((v: any) => v.Parent_ID == "0" || v.Parent_ID == null);
          if (filterData.length > 0) {
            proxy.$message.warning("选中数据中包含无父级数据，请检查数据是否正确");
            return;
          }
          proxy.dismantleSetting.visible = true;
          proxy.dismantleSetting.isTrue = false;
          proxy.dismantleSetting.type = "folder";
        }
        break;
      case "查询归卷":
        {
          proxy.queryTheVolumeSetting.visible = true;
          proxy.queryTheVolumeSelect = proxy.FMTData.filter(
            (v: any) => v.FMT_Parent_ID === proxy.tableSetting.rowClickObj.FMT_ID
          )[0].FMT_ID;
          proxy.queryTheVolumeRule = this.dynamicStore.childVisibleConfig;
          console.log(proxy.queryTheVolumeRule);
        }
        break;
      default:
        break;
    }
  }
  /**
   * @description 子级表格按钮功能实现
   * @param
   * @param
   * @returns
   */
  async ChildClickEvent(name: string, proxy: any) {
    const { userInfo } = this.userStore;
    proxy.dynamicModal.type = "child";
    const { childTableSelect } = this.dynamicStore;
    const stateNum: any = {
      Collect: 1,
      Arrangement: 2,
      Storage: 3,
      Utilization: 4
    };
    const defaultData = {
      Year: proxy.tableSetting.rowClickObj.Year,
      Code: proxy.tableSetting.rowClickObj.Code,
      Order: "",
      PageCount: "",
      Parent_ID: proxy.tableSetting.rowClickObj.Record_ID,
      Catalog_ID: proxy.tableSetting.rowClickObj.Catalog_ID,
      Status: stateNum[proxy.routeData.status],
      Create_DateTime: new Date()
    };
    switch (name) {
      case "新增":
        proxy.dynamicModal.title = "新增";
        vueAxios
          .post("Master_Base_EditorWindow/GetConditional", {
            order: "EW_Order asc",
            dtoList: [{ fieldName: "FMT_ID", fieldValue: proxy.childData[proxy.activeName].FMT_ID }]
          })
          .then((res: any) => {
            if (Object.keys(res.List).length > 0) {
              this.dynamicStore.setOldForm({});
              this.dynamicStore.setModalFormData(defaultData);
              const stateName: any = {
                Collect: "档案收集",
                Arrangement: "档案整理",
                Storage: "档案保存",
                Utilization: "档案利用"
              };

              res.List.forEach((item: any) => {
                if (item.EW_Type === stateName[this.fondsStore.fondsObj.Archive_Status]) {
                  proxy.dynamicModal.htmlCode = item.EW_Det;
                  proxy.$refs.dynamicForm.open();
                  proxy.dynamicModal.formType = 2;
                } else if (item.EW_Type === "空") {
                  proxy.dynamicModal.htmlCode = item.EW_Det;
                  proxy.dynamicModal.formType = 2;
                  proxy.$refs.dynamicForm.open();
                }
              });
            } else {
              proxy.$message.error("请前往窗口模型配置相关参数!");
            }
          });
        break;
      case "修改":
        proxy.dynamicModal.title = "修改";
        this.dynamicStore.setOldForm(cloneDeep(childTableSelect[0]));
        vueAxios
          .post("Master_Base_EditorWindow/GetConditional", {
            order: "EW_Order asc",
            dtoList: [{ fieldName: "FMT_ID", fieldValue: this.dynamicStore.childTableData[0].FMT_ID }]
          })
          .then((res: any) => {
            if (Object.keys(res.List[0]).length > 0) {
              this.dynamicStore.setModalFormData(cloneDeep(childTableSelect[0]));
              proxy.dynamicModal.htmlCode = res.List[0].EW_Det;
              proxy.$refs.dynamicForm.open();
              proxy.dynamicModal.formType = 2;
            } else {
              proxy.$message.error("请前往窗口模型配置相关参数!");
            }
          });
        break;
      case "克隆":
        proxy.dynamicModal.title = "克隆";
        vueAxios
          .post("Master_Base_EditorWindow/GetConditional", {
            order: "EW_Order asc",
            dtoList: [{ fieldName: "FMT_ID", fieldValue: childTableSelect[0].FMT_ID }]
          })
          .then((res: any) => {
            if (Object.keys(res.List[0]).length > 0) {
              // 触发字段规则校验函数
              // 获取启用的字段规则
              const stateNum: any = {
                Collect: 1,
                Arrangement: 2,
                Storage: 3,
                Utilization: 4
              };
              const newData = reactive({ ...childTableSelect[0], Status: stateNum[proxy.routeData.status] });
              const fieldRule = this.dynamicStore.childVisibleConfig.FieldRule.filter((v: any) => v.FR_Enable === true);
              const tableName = this.dynamicStore.childVisibleConfig.FMT.FMT_TableName;
              const newTestClass = new TestClass(newData, fieldRule, tableName);
              newTestClass.checkout();
              this.dynamicStore.setModalFormData(newData);
              proxy.dynamicModal.htmlCode = res.List[0].EW_Det;
              proxy.$refs.dynamicForm.open();
              proxy.dynamicModal.formType = 2;
            } else {
              proxy.$message.error("请前往窗口模型配置相关参数!");
            }
          });
        break;
      case "删除":
        proxy
          .$confirm("是否删除当前数据?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(async () => {
            const { childVisibleConfig, childTableSelect, childTableData } = this.dynamicStore;
            const { LoadingConfig } = this.appStore;
            let deleteFailed = false; // 定义一个变量来标记是否有删除失败
            // for (let i = 0; i < childTableSelect.length; i++) {
            //   LoadingConfig.contentLoading = true;
            //   LoadingConfig.contentTip = `删除数据${i}/${childTableSelect.length}`;
            //   const param = {
            //     list: [
            //       {
            //         Record_ID: childTableSelect[i].Record_ID,
            //         FMT_ID: childTableSelect[i].FMT_ID,
            //         FM_ID: childTableSelect[i].FM_ID,
            //         IsDelete: true
            //       }
            //     ],
            //     tableName: childVisibleConfig.FMT.FMT_TableName
            //   };
            //   const Res = await vueAxios.put("Dynamic", param, { noLoading: true });
            //   if (Res.Mark) {
            //     LoadingConfig.contentLoading = false;
            //     childTableData.splice(
            //       childTableData.findIndex((v: any) => v.Record_ID === childTableSelect[i].Record_ID),
            //       1
            //     );
            //   } else {
            //     deleteFailed = true; // 标记删除失败
            //   }

            // }
            // if (deleteFailed) {
            //   LoadingConfig.contentLoading = false;
            //   proxy.$message({
            //     type: "error",
            //     message: "删除失败!"
            //   });
            // } else {
            //   proxy.$message({
            //     type: "success",
            //     message: "删除成功!"
            //   });
            // }
            if (!proxy.singalrModal.AllNetworkStatus) {
              proxy.singalrModal.AllNetworkStatus = true;
              proxy.singalrModal.circulatingIndex = 0;
              proxy.singalrModal.percent = 0;
            }
            const copyData = cloneDeep(childTableSelect);
            for (let i = proxy.singalrModal.circulatingIndex; i < copyData.length; i++) {
              proxy.singalrModal.circulatingIndex = i;
              const item = copyData[i];
              proxy.singalrModal.text = `正在删除${proxy.singalrModal.circulatingIndex}个数据，档号为${item.Code}`;
              if (proxy.singalrModal.networkStatus && proxy.singalrModal.AllNetworkStatus) {
                const isDelete = getSysConfig("isShowRecycle");
                let Res;
                if (isDelete && isDelete.toLowerCase() === "true") {
                  Res = await proxy.$vueAxios.put(
                    "Dynamic",
                    {
                      list: [{ Record_ID: item.Record_ID, FMT_ID: item.FMT_ID, FM_ID: item.FM_ID, IsDelete: true }],
                      tableName: childVisibleConfig.FMT.FMT_TableName
                    },
                    { noLoading: true }
                  );
                } else {
                  Res = await proxy.$vueAxios.delete2(
                    "Dynamic",
                    {
                      list: [{ Record_ID: item.Record_ID, FMT_ID: item.FMT_ID, FM_ID: item.FM_ID, IsDelete: true }],
                      tableName: childVisibleConfig.FMT.FMT_TableName
                    },
                    { noLoading: true }
                  );
                }
                if (Res.Mark) {
                  this.dynamicStore.delTableSelectData(
                    childTableSelect.splice(
                      childTableSelect.findIndex((v: any) => v.Record_ID === item.Record_ID),
                      1
                    )
                  );
                  childTableData.splice(
                    childTableData.findIndex((v: any) => v.Record_ID === item.Record_ID),
                    1
                  );
                } else {
                  deleteFailed = true; // 标记删除失败
                }
                proxy.singalrModal.percent = Math.round(((proxy.singalrModal.circulatingIndex + 1) / copyData.length) * 100);
              } else {
                return;
              }
            }
            if (deleteFailed) {
              proxy.$message({
                type: "error",
                message: "删除失败!"
              });
            } else {
              proxy.$message({
                type: "success",
                message: "删除成功!"
              });
            }
            proxy.singalrModal.circulatingIndex = 0;
            proxy.singalrModal.percent = 0;
            proxy.singalrModal.visible = false;
            proxy.singalrModal.discontinueStatus = false;
            proxy.singalrModal.networkStatus = true;
            proxy.singalrModal.discontinueFont = "中止";
            proxy.singalrModal.AllNetworkStatus = false;
          });
        break;
      case "前端导出":
        if (childTableSelect.length === 0) {
          ElNotification.warning({
            title: "提示",
            message: "未选中任何数据!"
          });
          return false;
        }
        const catalogList = this.catalogStore.catalogList;
        const { childVisibleConfig } = this.dynamicStore;
        const fieldRule = childVisibleConfig.FieldRule.filter((v: any) => v.FR_Enable === true);
        const str = "DDM_Enable_Display_" + proxy.routeData.status;
        const filterColumns = this.dynamicStore.childVisibleConfig.DDMList.filter(
          (v: any) => v[str] === true && v.Field_Name !== "IsLock"
        );
        const header = filterColumns.map((v: any) => v.DDM_CNName);
        const filterVal = filterColumns.map((v: any) => v.Field_Name);
        const { LoadingConfig } = this.appStore;
        LoadingConfig.contentLoading = true;
        const data = childTableSelect.map((v: any) =>
          filterVal.map((j: string | number) => {
            for (let item of fieldRule) {
              if (item.FR_Rule.toLowerCase().includes("jm")) {
                v[j] = item.FR_TableField === j ? ACrypto.getSS(v[j]) : v[j];
              } else if (item.FR_Rule.toLowerCase().includes("userinfo:")) {
                // 人员的id转换
              } else if (item.FR_Rule.toLowerCase().includes("catalogconvert:")) {
                // 分类转换
                v[j] =
                  item.FR_TableField === j
                    ? catalogList.find((k: any) => k.Catalog_ID && k.Catalog_ID === v[j]).Catalog_Name
                    : v[j];
              } else if (item.FR_Rule.toLowerCase().includes("datetime:")) {
                // 时间转换
                v[j] = item.FR_TableField === j && v[j] ? dtime(v[j]).format("YYYY-MM-DD") : v[j];
              } else if (item.FR_Rule.includes("dictionary:")) {
                v[j] = item.FR_TableField === j ? columnCoverter(item.FR_Rule, v[j]) : v[j];
              }
            }
            return v[j];
          })
        );
        for (let i = 0; i < 5000; i++) {
          const percent = Math.ceil(((i + 1) / 5000) * 100);
          LoadingConfig.contentTip = `数据处理中...(${percent}%)`;
        }
        import("@/vendor/Export2Excel").then(excel => {
          excel.export_json_to_excel({
            header: header, //表头 必填
            data, //具体数据 必填
            filename: "子级表格业务数据表", //非必填
            autoWidth: true, //非必填
            bookType: "xlsx" //非必填
          });
          LoadingConfig.contentLoading = false;
        });
        break;
      case "修改分类":
        proxy.SortModalRef.open();
        break;
      case "打包":
        proxy.$showLoading({ tip: "正在打包..." });
        const params = {
          fmtId: childTableSelect[0].FMT_ID,
          ids: childTableSelect.map((v: any) => v.Record_ID),
          clientUser: proxy.signalr.connectionId,
          fonds_ID: childTableSelect[0].Fonds_ID,
          tableName: this.dynamicStore.childVisibleConfig.FMT.FMT_TableName
        };
        vueAxios.post("InterfaceDownload/DownloadZip", params, { noLoading: true }).then(res => {
          if (res.Mark) {
            proxy.$hideLoading();
            proxy.$message.success("打包成功!");
          }
        });
        break;
      case "打包下载全文":
        proxy.$showLoading({ tip: "正在打包..." });
        const params2 = {
          fmtId: childTableSelect[0].FMT_ID,
          ids: childTableSelect.map((v: any) => v.Record_ID),
          clientUser: proxy.signalr.connectionId,
          fonds_ID: childTableSelect[0].Fonds_ID,
          tableName: this.dynamicStore.childVisibleConfig.FMT.FMT_TableName
        };
        vueAxios.post("InterfaceDownload/GetZipByAllInfos", params2, { noLoading: true }).then(res => {
          if (res.Mark) {
            proxy.$hideLoading();
            proxy.$message.success("打包成功!");
          } else {
            proxy.$hideLoading();
            proxy.$message.error("打包失败!");
          }
        });
        break;
      case "移交下一环节":
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "核对数据";
        proxy.handoverSetting.data = childTableSelect;
        proxy.handoverSetting.type = "child";
        break;
      case "导出归档登记表":
        // if (childTableSelect.length === 0) {
        //   ElNotification.warning({
        //     title: "提示",
        //     message: "未选中任何数据!"
        //   });
        //   return false;
        // }
        // vueAxios.post("Excel/ExportFilingData", { list:childTableSelect }).then((res: any) => {});
        break;
      case "导出归档目录清单":
        if (childTableSelect.length === 0) {
          ElNotification.warning({
            title: "提示",
            message: "未选中任何数据!"
          });
          return false;
        }
        const fileData = await vueAxios.download("Excel/ExportListingData", { list: childTableSelect });
        const fileBlob = new Blob([fileData], { type: "application/octet-stream;charset=utf-8" });
        saveAs(fileBlob, "归档目录清单.xlsx");
        break;
      case "批量挂接全文":
        proxy.uploadConfig.visible = true;
        break;
      case "轨迹查看":
        proxy.TrailConfig.title = "轨迹查看";
        proxy.TrailConfig.data = childTableSelect[0];
        proxy.TrailRef.show();
        break;
      case "OCR":
        vueAxios
          .post(
            "MasterBaseSearchOCR/TableExecuteOCR",
            {
              tableName: proxy.FMTData.filter((v: any) => v.FMT_ID === proxy.routeData.fmtid)[0].FMT_TableName,
              clientUser: proxy.signalr.connectionId
            },
            {
              noLoading: true
            }
          )
          .then((res: any) => {});
        break;
      case "权限管理":
        proxy.AuthConfig.visible = true;
        proxy.AuthConfig.title = "权限管理";
        proxy.AuthConfig.type = "child";
        break;
      case "离线挂接":
        proxy.mountSetting.visible = true;
        proxy.mountConfig.type = "file";
        proxy.mountForm?.resetFields();
      case "复制":
        proxy.pasteSetting.is_Copy = true;
        proxy.$message.success("复制成功");
        this.dynamicStore.setChildCopyData(childTableSelect);
        break;
      case "粘贴":
        proxy.$messageBox
          .confirm(`你确定要粘贴${childTableSelect.length}项数据吗`, "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning"
          })
          .then(() => {
            proxy.pasteSetting.type = "file";
            proxy.pasteSetting.visible = true;
          });
        break;
      case "剪贴":
        proxy.pasteSetting.is_Copy = false;
        proxy.$message.success("剪切成功");
        this.dynamicStore.setChildCopyData(childTableSelect);
        break;
      case "流水操作":
        if (
          this.dynamicStore.childVisibleConfig.FieldRule.filter(
            (v: any) => v.FR_Enable === true && v.FR_TableField === "Order" && v.FR_RuleType === "trigger"
          ).length === 0
        ) {
          proxy.$message.error("大流水号规则未配置");
          return;
        }
        proxy.LSHSetting.type = 2;
        proxy.LSHSetting.visible = true;
        proxy.LSHSetting.orderType = "Order";
        proxy.LSHSetting.title = "大流水操作";
        proxy.LSHSetting.ruleList = this.dynamicStore.childVisibleConfig.FieldRule.filter((v: any) => v.FR_Enable === true);
        proxy.LSHSetting.tableName = this.dynamicStore.childVisibleConfig.FMT.FMT_TableName;
        console.log(this.dynamicStore.childVisibleConfig.FMT.FMT_TableName);

        const filedRule = removeBlock(
          this.dynamicStore.childVisibleConfig.FieldRule.filter(
            (v: any) => v.FR_Enable === true && v.FR_TableField === "Order"
          )[0].FR_Rule
        );
        const filedRuleArr = filedRule.split(":").slice(2);

        const dtoList = filedRuleArr.map((v: any) => ({
          fieldName: v,
          fieldValue: this.dynamicStore.childTableSelect[0][v],
          conditionalType: 0
        }));
        dtoList.push({ fieldName: "IsDelete", fieldValue: "nullorfalse", conditionalType: 0 });
        await vueAxios
          .post(
            `Dynamic/GetTableDataConditional?FMT_TableName=${this.dynamicStore.childVisibleConfig.FMT.FMT_TableName}`,
            {
              order: "Order asc",
              dtoList: [
                ...dtoList,
                { fieldName: "Parent_ID", fieldValue: proxy.childTableSetting.rowClickObj.Parent_ID, conditionalType: 0 }
              ],

              pageIndex: 1,
              pageSize: 30000
            },
            { noLoading: true }
          )
          .then((res: any) => {
            if (res.Mark) {
              proxy.LSHSetting.data = res.List;
            }
          });
        break;
      case "小流水操作":
        {
          if (
            this.dynamicStore.childVisibleConfig.FieldRule.filter(
              (v: any) => v.FR_Enable === true && v.FR_TableField === "SmallOrder" && v.FR_RuleType === "trigger"
            ).length === 0
          ) {
            proxy.$message.error("小流水号规则未配置");
            return;
          }
          proxy.LSHSetting.type = 2;
          proxy.LSHSetting.visible = true;
          proxy.LSHSetting.orderType = "SmallOrder";
          proxy.LSHSetting.title = "小流水操作";
          proxy.LSHSetting.ruleList = this.dynamicStore.childVisibleConfig.FieldRule.filter((v: any) => v.FR_Enable === true);
          proxy.LSHSetting.tableName = this.dynamicStore.childVisibleConfig.FMT.FMT_TableName;
          console.log(this.dynamicStore.childVisibleConfig.FMT.FMT_TableName);

          const filedRule = removeBlock(
            this.dynamicStore.childVisibleConfig.FieldRule.filter(
              (v: any) => v.FR_Enable === true && v.FR_TableField === "SmallOrder"
            )[0].FR_Rule
          );
          const filedRuleArr = filedRule.split(":").slice(2);
          console.log(filedRuleArr, filedRule);

          const dtoList = filedRuleArr.map((v: any) => ({
            fieldName: v,
            fieldValue: this.dynamicStore.childTableSelect[0][v],
            conditionalType: 0
          }));
          dtoList.push({ fieldName: "IsDelete", fieldValue: "nullorfalse", conditionalType: 0 });
          await vueAxios
            .post(
              `Dynamic/GetTableDataConditional?FMT_TableName=${this.dynamicStore.childVisibleConfig.FMT.FMT_TableName}`,
              {
                order: "Order asc",
                dtoList: [
                  ...dtoList,
                  { fieldName: "Parent_ID", fieldValue: proxy.childTableSetting.rowClickObj.Parent_ID, conditionalType: 0 }
                ],

                pageIndex: 1,
                pageSize: 30000
              },
              { noLoading: true }
            )
            .then((res: any) => {
              if (res.Mark) {
                proxy.LSHSetting.data = res.List;
              }
            });
        }
        break;
      case "标记备注":
        proxy.remarkForm?.resetFields();
        proxy.remarkSetting.visible = true;
        proxy.remarkSetting.type = "file";
        break;
      case "数据查重":
        proxy.dataCheckForm?.resetFields();
        proxy.dataCheckSetting.visible = true;
        proxy.dataCheckSetting.type = "file";
        break;
      case "查找替换":
        // proxy.ReplacementConfig.visible = true;
        proxy.ReplacementConfig.type = 2;
        proxy.replaceModal.show(proxy.childTableSetting.childColumns);
        break;
      case "文件锁定":
        let flag = false;
        flag = childTableSelect.every((v: any) => v.Collect_Create_By === userInfo.U_ID) || userInfo.U_IsAdministrator;
        if (!flag) {
          proxy.$alert("没有操作权限!", "提示", {
            confirmButtonText: "知道了",
            type: "warning"
          });
          return;
        }
        IsLockConcat("child", true).then(() => {
          proxy.$message.success("操作成功!");
        });
        break;
      case "文件解锁":
        let flag2 = false;
        flag2 = childTableSelect.every((v: any) => v.Collect_Create_By === userInfo.U_ID) || userInfo.U_IsAdministrator;
        if (!flag2) {
          proxy.$alert("没有操作权限!", "提示", {
            confirmButtonText: "知道了",
            type: "warning"
          });
          return;
        }
        IsLockConcat("child", false).then(() => {
          proxy.$message.success("操作成功!");
        });
        break;
      case "数据提交":
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "数据提交";
        proxy.handoverSetting.data = childTableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.retreat = false;
        break;
      case "数据撤回":
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "数据撤回";
        proxy.handoverSetting.data = childTableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.retreat = false;
        break;
      case "数据接收":
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "数据接收";
        proxy.handoverSetting.data = childTableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.retreat = false;
        break;
      case "数据退回":
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "数据退回";
        proxy.handoverSetting.data = childTableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.retreat = false;
        break;
      case "撤销接收":
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "撤销接收";
        proxy.handoverSetting.data = childTableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.retreat = false;
        break;
      case "移交入库":
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "移交入库";
        proxy.handoverSetting.data = childTableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.retreat = false;
        break;
      case "入库确认":
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "入库确认";
        proxy.handoverSetting.data = childTableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.retreat = false;
        break;
      case "撤销入库":
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "撤销入库";
        proxy.handoverSetting.data = childTableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.retreat = false;
        break;
      case "入库退回":
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "入库退回";
        proxy.handoverSetting.data = childTableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.retreat = false;
        break;
      case "数据开放":
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "数据开放";
        proxy.handoverSetting.data = childTableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.retreat = false;
        break;
      case "取消开放":
        proxy.handoverSetting.visible = true;
        proxy.handoverSetting.title = "取消开放";
        proxy.handoverSetting.data = childTableSelect;
        proxy.handoverSetting.type = "parent";
        proxy.handoverSetting.retreat = false;
        break;
      case "合卷":
        const ftmPid = proxy.FMTData.filter((v: any) => v.FMT_ID === proxy.routeData.fmtid)[0].FMT_Parent_ID;
        console.log(proxy.FMTData.filter((v: any) => v.FMT_ID === ftmPid));
        break;
      case "拆卷":
        {
          const filterData = childTableSelect.filter((v: any) => v.Parent_ID == "0" || v.Parent_ID == null);
          if (filterData.length > 0) {
            proxy.$message.warning("选中数据中包含无父级数据，请检查数据是否正确");
            return;
          }
          proxy.dismantleSetting.visible = true;
          proxy.dismantleSetting.isTrue = false;
          proxy.dismantleSetting.type = "child";
        }
        break;
      case "查询归卷":
        break;
      default:
        break;
    }
  }
  /**
   * @description excel导入
   * @param
   * @param
   * @returns
   */
  async ExportExcel(files: any, proxy: any) {
    const fileData = new FormData();
    const stateNum: any = {
      Collect: 1,
      Arrangement: 2,
      Storage: 3,
      Utilization: 4
    };
    fileData.append("FormCollection", files[0]);
    fileData.append("Fonds_ID", this.catalogStore.treeNode.Fonds_ID);
    fileData.append("Catalog_ID", this.catalogStore.treeNode.Catalog_ID);
    fileData.append("Status", stateNum[proxy.routeData.status]);
    fileData.append("FMT_ID", proxy.routeData.fmtid);
    vueAxios.post("Excel/ImportExcelData", fileData).then((res: any) => {
      if (res.Mark) {
        proxy.getPageData();
      } else {
        proxy.getPageData();
        // proxy.$message.warning(`${res.Msg}:${res.List.filter((m: any, i: number) => i <= 2)}`);
        // 使用 slice 方法获取前三个元素
        const firstThreeMessages = res.List.slice(0, 1);
        // 拼接字符串并显示警告
        const warningMessage = `${res.Msg}:${firstThreeMessages.map((m: any) => m.toString()).join(", ")}`;
        proxy.$message.warning(warningMessage);
      }
    });
  }
  /**
   * @description 批量挂接全文
   * @param
   * @param
   * @returns
   */
  async uploadZipEvent(files: any, proxy: any) {
    const _files = [...files]; // 复制数组,防止数据丢失
    const filesLength = _files.length;
    proxy.fulltextModal.percent = 0;
    let fileCount = 0;
    const errorList = [];
    let bytesPerPiece = 1024 * 1024 * 10; // 每个文件切片大小定为10MB
    let totalPieces: any;
    const stateNum: any = {
      Collect: 1,
      Arrangement: 2,
      Storage: 3,
      Utilization: 4
    };
    for (let i = 0; i < _files.length; i++) {
      // 单文件分片上传
      let blob = _files[i];
      let start = 0;
      let end;
      let progressIndex = 1;
      let filesize = blob.size;
      // 计算文件切片总数
      totalPieces = Math.ceil(filesize / bytesPerPiece);
      const AIID = global.createID();
      for (let uploadIndex: any = 1; uploadIndex <= totalPieces; uploadIndex++) {
        end = Math.min(filesize, start + bytesPerPiece);
        let chunk = blob.slice(start, end); // 切割文件
        const fileData = new FormData();
        fileData.append("file", chunk);
        fileData.append("PieceTotal", totalPieces);
        fileData.append("PieceNow", uploadIndex);
        fileData.append("AI_ID", AIID);
        fileData.append("FM_ID", proxy.routeData.fmid);
        fileData.append("AI_Name", blob.name);
        fileData.append("Status", stateNum[proxy.routeData.status]);
        fileData.append("IsCover", proxy.uploadConfig.isCover);
        fileData.append("ClientUser", proxy.signalr.connectionId);
        proxy.fulltextModal.isShow = true;
        const Res = await vueAxios.post("MasterBaseAllInfos/RearUploadFileByPiece", fileData, { noLoading: true });
        if (!Res.Mark) {
          errorList.push(Res.Msg);
        }
        start = start + chunk.size;
        proxy.fulltextModal.percent = Math.round((progressIndex / totalPieces / filesLength) * 100);
        progressIndex++;

        // 单个文件传输完成
        if (uploadIndex >= totalPieces) {
          fileCount++;
        }
        // 所有文件传输完成
        if (fileCount >= filesLength) {
          proxy.fulltextModal.isShow = false;
          if (errorList.length > 0) {
            ElNotification.warning({
              title: "上传失败!",
              message: JSON.stringify(errorList)
            });
          }
        }
      }
    }
  }
  /**
   * @description 生成报表
   * @param
   * @param
   * @returns
   */
  async reportModuleClickEvent(ID: string, reportForm: any, type: string) {
    const ReportClass = new ReportFormClass();
    const result = await ReportClass.analyseRepot(reportForm, type);
    console.log(result);
    if (result && result.List) {
      const limitLength = result.List.length;
      console.log("报表限制长度", limitLength);
      if (limitLength > result.RowNumber) {
        ElMessageBox.confirm("该操作需要时间较长,可以在报表下载管理中刷新列表进行下载!", {
          confirmButtonText: "确认",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          vueAxios
            .download(
              "Excel",
              {
                list: result.List,
                rM_ID: reportForm.RM_ID,
                fileName: reportForm.RM_FileName,
                constantList: result.Constants,
                fM_ID: result.FM_ID,
                fonds_ID: this.fondsStore.fondsObj.Fonds_ID
                // tableName: result.TableName
              },
              { noLoading: true }
            )
            .then((res: any) => {
              this.appStore.LoadingConfig.contentLoading = false;
              const fileBlob = new Blob([res], { type: "application/octet-stream;charset=utf-8" });
              saveAs(fileBlob, `${reportForm.RM_FileName}`);
            });
        });
      } else {
        this.appStore.LoadingConfig.contentLoading = true;
        this.appStore.LoadingConfig.contentTip = "正在生成报表...";
        vueAxios
          .download(
            "Excel",
            {
              list: result.List,
              rM_ID: reportForm.RM_ID,
              fileName: reportForm.RM_FileName,
              constantList: result.Constants,
              fM_ID: result.FM_ID,
              fonds_ID: this.fondsStore.fondsObj.Fonds_ID
              // tableName: result.TableName
            },
            { noLoading: true }
          )
          .then((res: any) => {
            this.appStore.LoadingConfig.contentLoading = false;
            const fileBlob = new Blob([res], { type: "application/octet-stream;charset=utf-8" });
            saveAs(fileBlob, `${reportForm.RM_FileName}`);
          });
      }
    } else {
      ElMessage({
        type: "warning",
        message: "请选中导出数据"
      });
    }
  }
}
